<?php
/**
 * @file tryapplyuserinfo.php $
 * @author LiangJian (liangjian@haibao.com) $
 * @date 2015-4-21 下午3:54:43 $
 * @brief 试用中心申请用户数据层 $
 */
namespace haibao\cms\data;


class TryApplyUserInfo extends \haibao\cms\data\BaseMysql{
	
	public function __construct(){
		parent::__construct('\haibao\cms\model\data\TryApplyUserInfo');
	}
	
	/**
	 * 根据用户id查询已经申请用户填写过的个人信息
	 * @param int $userId
	 * @return array
	 */
	public function getUserById($userId){
		$sql = "select *,a.Id as tid from TryApplyUserInfo as a left join TryApply as b on a.UserId=b.UserId where a.UserId=%s ORDER BY a.LastModifyTime DESC limit 1";
		$result = $this->query($sql, array($userId));
		return $result->fetch_assoc();
	}
	
	public function addUserInfo($model){
		$this->add($model);
	}
	
	/**
	 * 根据用户id更改用户详细个人信息
	 * @param \haibao\cms\model\data\TryApplyUserInfo $model
	 */
	public function updateByUserId($model){
		if($model->Id && $model->UserId){
			$this->updateById($model->Id, array(
			    \haibao\cms\model\filter\TryApplyUserInfo::CONDITION_FIELD_NAME_TRY_ID => $model->TryId,
				\haibao\cms\model\filter\TryApplyUserInfo::CONDITION_FIELD_NAME_SKIN => $model->Skin,
				\haibao\cms\model\filter\TryApplyUserInfo::CONDITION_FIELD_NAME_HAIR => $model->Hair,
				\haibao\cms\model\filter\TryApplyUserInfo::CONDITION_FIELD_NAME_CONSUME => $model->Consume,
				\haibao\cms\model\filter\TryApplyUserInfo::CONDITION_FIELD_NAME_SALARY  => $model->Salary,
				\haibao\cms\model\filter\TryApplyUserInfo::CONDITION_FIELD_NAME_EDUCATION => $model->Education,
				\haibao\cms\model\filter\TryApplyUserInfo::CONDITION_FIELD_NAME_MAKEUP => $model->Makeup,
				\haibao\cms\model\filter\TryApplyUserInfo::CONDITION_FIELD_NAME_PERFUME => $model->Perfume,
				\haibao\cms\model\filter\TryApplyUserInfo::CONDITION_FIELD_NAME_BUYTYPE => $model->BuyType,
				\haibao\cms\model\filter\TryApplyUserInfo::CONDITION_FIELD_NAME_HOPE => $model->Hope,
				\haibao\cms\model\filter\TryApplyUserInfo::CONDITION_FIELD_NAME_BIRTHDAY => $model->Birthday,
				\haibao\cms\model\filter\TryApplyUserInfo::CONDITION_FIELD_NAME_SEX => $model->Sex,
				\haibao\cms\model\filter\TryApplyUserInfo::CONDITION_FIELD_NAME_REALNAME => $model->RealName,
				\haibao\cms\model\filter\TryApplyUserInfo::CONDITION_FIELD_NAME_PROVINCE => $model->Province,
				\haibao\cms\model\filter\TryApplyUserInfo::CONDITION_FIELD_NAME_CITY => $model->City,
				\haibao\cms\model\filter\TryApplyUserInfo::CONDITION_FIELD_NAME_AREA => $model->Area,
				\haibao\cms\model\filter\TryApplyUserInfo::CONDITION_FIELD_NAME_ADDRESS => $model->Address,
				\haibao\cms\model\filter\TryApplyUserInfo::CONDITION_FIELD_NAME_ZIPCODE => $model->ZipCode,
				\haibao\cms\model\filter\TryApplyUserInfo::CONDITION_FIELD_NAME_PHONE => $model->Phone,
				\haibao\cms\model\filter\TryApplyUserInfo::CONDITION_FIELD_NAME_EMAIL => $model->Email,
				\haibao\cms\model\filter\TryApplyUserInfo::CONDITION_FIELD_NAME_LAST_MODIFY_TIME => new \DateTime(),
			));
		}
	}
	
}